Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

helper-cache

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

helper-cache

Easily register and get helper functions to be passed to any template engine or node.js application. Methods for both sync and async helpers.

  • 0.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33K
increased by3.37%
Maintainers
2
Weekly downloads
 
Created
Source

helper-cache NPM version

Easily register and get helper functions to be passed to any template engine or node.js application. Methods for both sync and async helpers.

Install with npm

npm i helper-cache --save

Usage

Helpers

Create an instance of Helpers, optionally passing default options.

  • options {Object}: Default options to use.
    • bind {Boolean}: Bind functions to this. Defaults to false.
    • thisArg {Boolean}: The context to use.
var Helpers = require('helper-cache');
var helpers = new Helpers();

addHelper

Register a helper.

  • name {String}: The name of the helper.
  • fn {Function}: Helper function.
helpers.addHelper('lower', function(str) {
  return str.toLowerCase();
});

addAsyncHelper

Register an async helper.

  • key {String}: The name of the helper.
  • fn {Function}: Helper function.
helpers.addAsyncHelper('foo', function (str, callback) {
  callback(null, str + ' foo');
});

addHelpers

Load a glob or object of helpers.

  • key {String}: The name of the helper.
  • fn {Function}: Helper function.
// glob patterns
helpers.addHelpers('helpers/*.js');
helpers.addHelpers(['helpers/a.js', 'helpers/{b,c}.js']);
// object of helper functions
helpers.addHelpers({
  a: function() {},
  b: function() {},
  c: function() {},
});

See load-helpers for issues, API details and the full range of options.

addAsyncHelpers

Load a glob or object of async helpers.

  • key {String}: The name of the helper.
  • fn {Function}: Helper function.
// glob patterns
helpers.addAsyncHelpers('helpers/*.js');
helpers.addAsyncHelpers(['helpers/a.js', 'helpers/{b,c}.js']);
// object of helper functions
helpers.addAsyncHelpers({
  a: function() {},
  b: function() {},
  c: function() {},
});

See load-helpers for issues, API details and the full range of options.

getHelper

Get a registered helper.

  • key {String}: The helper to get.
  • returns {Object}: The specified helper. If no key is passed, the entire cache is returned.
helpers.getHelper('foo');

getAsyncHelper

Get a registered async helper.

  • key {String}: The helper to get.
  • returns {Object}: The specified helper. If no key is passed, the entire cache is returned.
helpers.getAsyncHelper('foo');

resolveHelper

Getter method to resolve async helper values that were called during the render process. Rendering is done by whatever engine you've registered the helpers with.

  • content {String}: Rendered string containing async ids
  • cb {Function}
helper.resolveHelper(str, function (err, content) {
  if (err) return done(err);
  // do stuff with `content`
  done();
});

Author

Jon Schlinkert

Brian Woodward

License

Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb on February 14, 2015.

Keywords

FAQs

Package last updated on 19 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc